package com.wanka.jutou.config;

import com.wanka.jutou.factorybean.RedisDataSourceFactoryBean;

import java.time.Duration;
import java.util.List;

/**
 * @author yangqing
 * @version 1.0
 * @date 2025/9/1 17:22
 * @description
 */
public class RedisDataSourceProperties extends AbstractDataSourceProperties {
    private String host = "localhost";
    private int port = 6379;
    private String password;
    private int database;
    private Duration timeout;
    private List<String> nodes;
    private String ruleKey;
    private String channel;
    private String masterId;

    public RedisDataSourceProperties() {
        super(RedisDataSourceFactoryBean.class.getName());
    }

    public void preCheck(String dataSourceName) {
        super.preCheck(dataSourceName);
        if (StringUtils.isEmpty(this.ruleKey)) {
            throw new IllegalArgumentException("RedisDataSource  ruleKey can not be empty");
        } else if (StringUtils.isEmpty(this.channel)) {
            throw new IllegalArgumentException("RedisDataSource  channel can not be empty");
        } else if (StringUtils.isEmpty(this.masterId)) {
            throw new IllegalArgumentException("RedisDataSource  sentinel model，masterId can not be empty");
        }
    }

    public String getHost() {
        return this.host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return this.port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getRuleKey() {
        return this.ruleKey;
    }

    public void setRuleKey(String ruleKey) {
        this.ruleKey = ruleKey;
    }

    public String getChannel() {
        return this.channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getDatabase() {
        return this.database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public Duration getTimeout() {
        return this.timeout;
    }

    public void setTimeout(Duration timeout) {
        this.timeout = timeout;
    }

    public List<String> getNodes() {
        return this.nodes;
    }

    public void setNodes(List<String> nodes) {
        this.nodes = nodes;
    }

    public String getMasterId() {
        return this.masterId;
    }

    public void setMasterId(String masterId) {
        this.masterId = masterId;
    }
}
